Helpful Information
 
 
Category: JavaScript Development
is it possible to get the X & Y co-ordinates of an anchor \ image in Javascript ???

hey..

i`m looking for a peice of code to get the X & Y co-ords of an image or Anchor in Javascript, i figuire its got to be possible.. i`m just not entirely sure how.. if anyone could help me out here it would be much appreciated http://www.devshed.com/Talk/Forums/smile.gif

Apoc

Yes, you can! I have an example at http://www.sitesuwant.com/exampleXY.html. (http://www.sitesuwant.com/exampleXY.html) You can get the x and y of an image with this code inside the script tag:

document.theForm.xCoor.value=window.event.x;
document.theForm.xCoor.value=window.event.y;

In the body:

<b>Click X:</b> <input type="Text" name="xCoor" disabled><br>
<b>Click Y:</b> <input type="Text" name="yCoor" disabled>

...and that should give you the proper response. This will only work in Internet Explorer 3+ I believe, so if you want Netscape too, tell me and I'll try to figure something out in Javascript for Netscape...

Devin www.sitesuwant.com (http://www.sitesuwant.com)
sitesuwant@sitesuwant.com

[This message has been edited by kenowhere (edited September 04, 2000).]










privacy (GDPR)